<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<style>
			html,body {
				background-color: #efeff4;
			}
		</style>
		<script>
			mui.init();
		</script>
	</head>

	<body>

<header class="mui-bar mui-bar-nav">
	<a class="mui-action-menu mui-icon mui-icon-bars mui-pull-left"></a>
	<a class="mui-action-back mui-btn mui-btn-link mui-pull-right">关闭</a>
	<h1 class="mui-title">off canvas（侧滑导航）</h1>
</header>
<div class="mui-content">
	<ul class="mui-table-view mui-table-view-chevron mui-hidden">
		<li id="switch" class="mui-table-view-cell">
			整体滑动
			<div class="mui-switch">
				<div class="mui-switch-handle"></div>
			</div>
		</li>
	</ul>
	<ul class="mui-table-view mui-table-view-chevron">
		<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right">
				<img class="mui-media-object mui-pull-left" src="../images/42x42.gif">
				<div class="mui-media-body">
					Item 1
					<p>
						Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore. Lorem ipsum dolor sit amet.
					</p>
				</div>
			</a>
		</li>
		<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right">
				<img class="mui-media-object mui-pull-left" src="../images/42x42.gif">
				<div class="mui-media-body">
					Item 1
					<p>
						Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore. Lorem ipsum dolor sit amet.
					</p>
				</div>
			</a>
		</li>
		<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right">
				<img class="mui-media-object mui-pull-left" src="../images/42x42.gif">
				<div class="mui-media-body">
					Item 1
					<p>
						Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore. Lorem ipsum dolor sit amet.
					</p>
				</div>
			</a>
		</li>
		<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right">
				<img class="mui-media-object mui-pull-left" src="../images/42x42.gif">
				<div class="mui-media-body">
					Item 1
					<p>
						Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore. Lorem ipsum dolor sit amet.
					</p>
				</div>
			</a>
		</li>
		<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right">
				<img class="mui-media-object mui-pull-left" src="../images/42x42.gif">
				<div class="mui-media-body">
					Item 1
					<p>
						Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore. Lorem ipsum dolor sit amet.
					</p>
				</div>
			</a>
		</li>
		<li class="mui-table-view-cell mui-media">
			<a class="mui-navigate-right">
				<img class="mui-media-object mui-pull-left" src="../images/42x42.gif">
				<div class="mui-media-body">
					Item 1
					<p>
						Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore. Lorem ipsum dolor sit amet.
					</p>
				</div>
			</a>
		</li>
	</ul>
</div>
<script>
	mui.init({
		swipeBack: false
	});
	//整体滑动暂不支持android手机，因为两个页面的移动动画，无法保证同步性；
	if (!mui.os.android) {
		document.getElementById("switch").parentNode.classList.remove('mui-hidden');
	}
	var menu, showMenu = false,
		slideTogether = false;
	window.addEventListener('pagebeforeshow', function() {
		var left = '0%';
		if (slideTogether) {
			left = '-70%';
		}
		menu = mui.openWindow({
			id: 'offcanvas-plus-menu',
			url: 'offcanvas-plus-menu.html',
			styles: {
				left: left,
				width: '70%',
				zindex: 9998
			},
			show:{
				aniShow:'none'
			},
			waiting:{
				autoShow:false
			}
		});
		//初始化主页面位置
		mui.currentWebview.setStyle({
			left: 0
		});
	});
	document.querySelector('.mui-icon-bars').addEventListener('tap', function() {
		mui.currentWebview.setStyle({
			left: showMenu ? '0' : '70%',
			transition: {
				duration: 200
			}
		});
		//如果整体移动，则menu页面也需要移动；
		if (slideTogether) {
			menu.setStyle({
				left: showMenu ? '-70%' : '0%',
				transition: {
					duration: 200
				}
			});
		}
		showMenu = !showMenu;
	});

	function closeMenu() {
			menu.close('none');
		}
		//按返回图标时，关闭菜单webview
	document.querySelector('.mui-action-back').addEventListener('tap', closeMenu);
	mui.plusReady(function() {
		//按返回键时，关闭菜单webview
		plus.key.addEventListener('backbutton', closeMenu, false);
	});
	//整体切换开关事件，按下时，需变换menu界面的初始化位置；
	document.getElementById("switch").addEventListener('toggle', function(event) {
		if (event.detail.isActive) {
			//切换为整体移动
			//首先改变移动标志
			slideTogether = true;
			//变换menu界面初始化位置，整体移动时，Menu界面left需要在-70%的地方；
			menu.setStyle({
				left: '-70%'
			});
		} else {
			slideTogether = false;
			menu.setStyle({
				left: '0%'
			});
		}
	});
</script>

</body>
</html>